<template>
  <el-dialog :visible.sync="visible" width="80%" custom-class="default-dialog" :close-on-click-modal="false"
    @close="cancel" append-to-body v-dialogDrags>
    <div slot="title">
      <img v-if="type" :src="require(`@/assets/img/${type}.png`)" alt="">
      <span>{{ title }} </span>
    </div>
    <el-form :model="form" :rules="rules" ref="form" label-width="130px" class="dialog-form" :disabled="type == 'view'">

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="取水户编码" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入取水户编码"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="取水权力人名称" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入取水权力人名称"></el-input>
          </el-form-item>
        </el-col>
        </el-row>   

        <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="取水口编码" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入取水口编码"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="取水口名称" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入取水口名称"></el-input>
          </el-form-item>
        </el-col>
        </el-row>   

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="行政单元" prop="dictName">
            <el-cascader v-model="form.basinUnit" :options="basinOptions" placeholder="请选择" clearable></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="流域单元" prop="dictName">
            <el-cascader v-model="form.basinUnit" :options="basinOptions" placeholder="请选择" clearable></el-cascader>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="统计水量" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入统计水量"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="统计用途 " prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入储水水量"></el-input>
          </el-form-item>
        </el-col>
     
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="储水水量" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入储水水量"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="引水水量 " prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入储水水量"></el-input>
          </el-form-item>
        </el-col>
     
      </el-row>
    
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="提水水量" prop="dictName">
            <el-input v-model="form.dictName" placeholder="请输入提水水量"></el-input>
          </el-form-item>
        </el-col>
     
      </el-row>

    </el-form>
    <span slot="footer">
      <el-button size="small" @click="cancel">取 消</el-button>
      <el-button size="small" v-if="type != 'view'" type="primary" @click="sure">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      visible: false,
      title: '',
      form: {
        dictName: '',
        basinUnit: [],
        monitoringTime: ''
      },
      basinOptions: [
        {
          value: 'option1',
          label: '流域1',
          children: [
            {
              value: 'option1-1',
              label: '子流域1-1',
              children: [
                {
                  value: 'option1-1-1',
                  label: '单元1-1-1'
                }
              ]
            }
          ]
        },
        {
          value: 'option2',
          label: '流域2',
          children: [
            {
              value: 'option2-1',
              label: '子流域2-1',
              children: [
                {
                  value: 'option2-1-1',
                  label: '单元2-1-1'
                }
              ]
            }
          ]
        }
      ],options5: [{
          value: '1',
          label: '工业使用'
        }, {
          value: '2',
          label: '日常使用'
        }, {
          value: '3',
          label: '灌溉使用'
        }],
      rules: {
        dictName: [{ required: true, message: '请输入字典名称', trigger: 'blur' }]
      },
      type: ''
    };
  },
  methods: {
    showModal(type, row) {
      this.visible = true
      this.type = type
      if (type == 'add') {
        this.title = '新增'
        this.form = {
          "dictName": "",
          "remark": "",
        }
      } else if (type == 'edit') {
        this.title = '编辑'
        this.getInfoInit(row.sysDictId)
      } else if (type == 'view') {
        this.title = '详情'
        this.getInfoInit(row.sysDictId)
      }
    },
    // 详情
    getInfoInit(id) {
      this.$api.getDictInfo({ id: id }).then(res => {
        if (res && res.code == 200) {
          let data = res.data || {}
          this.form = data
        }
      })
    },
    // 确定
    sure() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.type == 'add') {
            this.$api.addDict(this.form).then(res => {
              if (res && res.code == 200) {
                this.$notify.success({
                  title: '成功',
                  message: '数据保存成功'
                });
                this.visible = false
                this.$emit('listInit')
              }
            })
          } else if (this.type == 'edit') {
            this.$api.updateDict(this.form).then(res => {
              if (res && res.code == 200) {
                this.$notify.success({
                  title: '成功',
                  message: '数据保存成功'
                });
                this.visible = false
                this.$emit('listInit')
              }
            })
          }
        }
      });
    },
    // 取消
    cancel() {
      this.visible = false;
      this.$refs["form"].resetFields();
    },
  }
};
</script>
<style lang="less" scoped>
.el-form-item__label {
  width: 150px;
}
</style>